//=========================验证账号登录=====================================
$(".login-btn").click(function () {
    getUsername()
    getPassword()
    login()

})
function login() {
    var custLoginAccount = $(".username").val()
    console.log(custLoginAccount);
    var custPassword = $(".userPassword").val()
    console.log(custPassword);
     //正则表达式 0:手机 ， 1 邮箱 2 用户名
    var type
    var account = custLoginAccount

    if (/^[1][3,4,5,7,8][0-9]{9}$/.test(custLoginAccount)){
        type = 0
        console.log("abc123");
        console.log(type);
    }

    else if (/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/.test(custLoginAccount))
        type = 1
    else
        type = 2
    var formdata = "op=login&type="+type+"&account="+account+"&custPassword="+custPassword
    console.log(formdata);

    $.ajax({
        type:"post",
        url:"/customer/login",
        data:formdata,
        datatype:"json",
        success:function (result) {
            console.log(result);
            if (result.status == 0){//登录失败，用户与或密码错误
                $(".loginMsg").text(result.data);
                console.log(result.data);
                console.log("登陆失败。。。。。");
            }else {//登录成功，跳转到首页
                $(".loginMsg").text("");
                console.log("登录成功");
                window.location.href="/index";
            }
        }
    })
}
//验证账号
function getUsername(){
    var usernameEle = $(".username");
    var username =$(".username").val();
    var ele
    var accountError = $(".accountError")
    accountError.html("")
    if(username.trim() ==null || username.trim() ==""){
            ele ="<span class=\"error_logo\"></span>\n" +
            "                        <span>请输入51Job账号</span>"
        accountError.html(ele)
        accountError.css("display","block")
        return false;
    }else if(!/^[1][3,4,5,7,8][0-9]{9}$/.test(username)){
        ele ="<span class=\"error_logo\"></span>\n" +
            "                        <span>请输入正确账号</span>"
        accountError.html(ele)
        accountError.css("display","block")
        return false;
    }else{
        accountError.html("")
        accountError.css("display","none")
        return true;
    }
}
//验证密码登录密码
function getPassword(){
    var usepwdEle = $(".userPassword");
    var usepwd =$(".userPassword").val()
    var userpwdErrorEle = $(".mima")

    var ele
    userpwdErrorEle.html("")
    if(usepwd.trim() ==null || usepwd.trim() ==""){
        ele ="<span class=\"error_logo\"></span>\n" +
            "                        <span>请输入密码</span>";
        userpwdErrorEle.html(ele)
        userpwdErrorEle.css("display","block")

    }else if(!/^[0-9A-Za-z]{6,12}$/.test(usepwd)){
        ele ="<span class=\"error_logo\"></span>\n" +
            "         <span>用户名长度在6-12个字符，由数字与字母组成</span>"
        userpwdErrorEle.html(ele)
        userpwdErrorEle.css("display","block")

    }else{
        userpwdErrorEle.html("")
        userpwdErrorEle.css("display","none")
    }
}

//=======================切换账号登录密码登录================================
document.querySelector(".new-kind").onclick = function () {
    if (document.querySelector("#login-ByPassword").style.display == "none") {


        document.querySelector("#login-ByPassword").style.display = "block";
        document.querySelector("#login-ByCode").style.display = "none";
        document.querySelector(".now-kind").innerText = "密码登录";
        document.querySelector(".new-kind").innerText = "验证码登录";
    } else {
        document.querySelector("#login-ByPassword").style.display = "none";
        document.querySelector("#login-ByCode").style.display = "block";
        document.querySelector(".now-kind").innerText = "验证码登录";
        document.querySelector(".new-kind").innerText = "密码登录";
    }
}

//========================验证验证码登录========================================